<?php

class StatsController extends Zend_Controller_Action {

    public function cumulvisiteurAction() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = "Select idVisiteur, mois, count(*) as nbFiches, sum(montantValide) as total
            From ficheFrais
            Where idEtat='RB'
            Group By idVisiteur, mois
            Order By idVisiteur";
        $lesStats = $db->fetchAll($query);
        $this->view->lesStats = $lesStats;
    }

    public function cumulfraisAction() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = "Select idVisiteur, mois, 
    SUM(CASE idFraisForfait when 'ETP' THEN quantite*montant END ) as ETP,
    SUM(CASE idFraisForfait when 'KM' THEN quantite*montant END ) as KM,
    SUM(CASE idFraisForfait when 'NUI' THEN quantite*montant END ) as NUI,
    SUM(CASE idFraisForfait when 'REP' THEN quantite*montant END ) as REP
    From fraisforfait join lignefraisforfait on id = lignefraisforfait.idfraisforfait
    Group by idVisiteur, mois";
        $lesStats = $db->fetchAll($query);
        $this->view->lesStats = $lesStats;
    }

}

